home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1991: Code Warrior / bincue / Code Warrior.bin / Developer Essentials / DTS Sample Code / Snippets / Snippets May '91 / Heap Purge dcmd / hp.a next >
Encoding:
Text File  |  1991-09-09  |  3.4 KB  |  110 lines  |  [TEXT/MPS ]

  1. -----------
  2. File: HP.a
  3. -----------
  4.             include        'SysErr.a'
  5.             include        'SysEqu.a'
  6.             include        'Traps.a'
  7.  
  8. allRegs        REG            D0-D7/A0-A5
  9.  
  10.             proc
  11.             
  12.             import        PurgeAllBlocks
  13.             
  14. ; ————————————————————————————————————————————————————————————————————————————
  15. ;
  16.  
  17.             export    SaveMyA5, GetMyA5
  18.             
  19. pMyA5        dc.l    0
  20.  
  21. SaveMyA5
  22.             lea        pMyA5,A0
  23.             move.l    A5,(A0)
  24.             rts
  25.             
  26. GetMyA5
  27.             move.l    pMyA5,4(SP)
  28.             rts
  29.  
  30.  
  31. ; ————————————————————————————————————————————————————————————————————————————
  32. ;
  33. ; Storage for the old patch addresses, used to call through once the patch 
  34. ; code executes. These are essentially globals, used by the asm code. They are 
  35. ; specifically not exported, so that the Pascal code cannot access them 
  36. ; directly. There are a number of interface routines I set up so that Pascal 
  37. ; can get and set them, but has to go through this file. You know, sort of 
  38. ; object like.
  39. ;
  40. pFirstSavedTrap           equ         *
  41. pOldNewPtr                dc.l        0
  42. pOldNewHandle             dc.l        0
  43. pOldReallocHandle         dc.l        0
  44. pOldSetPtrSize            dc.l        0
  45. pOldSetHandleSize         dc.l        0
  46. pOldMoveHHi               dc.l        0
  47.  
  48. ; ————————————————————————————————————————————————————————————————————————————
  49. ; When I'm am setting up the world, I call NGetTrapAddress to get the old 
  50. ; version of the traps. I need to save that dude off so I can get back there 
  51. ; when needed. This routine is a handy interface to the high-level world, 
  52. ; isolating this asm junk from the code. All these routines are the same, just 
  53. ; a different variable being affected. This hunk uses the PC-Relative 
  54. ; addressing mode in order to get the address of the variable being set. This 
  55. ; allows the code to function without any explicit global space, since the 
  56. ; code acts like globals here.
  57. ;
  58. ; The interface is:
  59. ;
  60. ;    PROCEDURE  SaveOldTrapAddress (address: LongInt; addressKind: Integer);
  61. ;
  62.  
  63.             export        SaveOldTrapAddress
  64.  
  65. SaveOldTrapAddress
  66.             MOVE.L        (SP)+,A0               ; get the return address
  67.             move.w        (SP)+,D0
  68.             asl.w         #2,D0
  69.             LEA           pFirstSavedTrap,A1     ; the variable to be setting
  70.  
  71.             MOVE.L        (SP)+,(A1,D0.w)   ; save it, pulling parameter too
  72.             JMP           (A0)              ; it's saved, return to high-level
  73.  
  74.             export        NewNewPtr, NewNewHandle, NewReallocHandle
  75.             export        NewSetPtrSize, NewSetHandleSize, NewMoveHHi
  76.  
  77. NewNewPtr
  78.             move.l        pOldNewPtr,-(SP)
  79.             bra.s         Common
  80.  
  81. NewNewHandle
  82.             move.l        pOldNewHandle,-(SP)
  83.             bra.s         Common
  84.  
  85. NewReallocHandle
  86.             move.l        pOldReallocHandle,-(SP)
  87.             bra.s         Common
  88.  
  89. NewSetPtrSize
  90.             move.l        pOldSetPtrSize,-(SP)
  91.             bra.s         Common
  92.  
  93. NewSetHandleSize
  94.             move.l        pOldSetHandleSize,-(SP)
  95.             bra.s         Common
  96.  
  97. NewMoveHHi
  98.             move.l        pOldMoveHHi,-(SP)
  99. ;            bra.s        Common
  100.  
  101. Common
  102.             movem.l       allRegs,-(SP)
  103.             move.w        D1,-(SP)
  104.             bsr           PurgeAllBlocks
  105.             movem.l       (SP)+,allRegs
  106.             rts
  107.  
  108.             ENDP
  109.             END
  110.